package com.wedata.腾讯;

import cn.hutool.core.text.UnicodeUtil;
import cn.hutool.crypto.digest.MD5;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.wedata.HttpUtils;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public class 微伴助手 {

    public static void main(String[] args) throws IOException {
        同步微伴标签();
        //员工列表();
        //查询预打标签();
        //删除预打标签任务();
        //批量预打标();
        //任务详情();
        //删除客户的企业标签();
        //删除预打标签任务();
        //任务详情();
        //System.out.println(getToken2());
    }

    public static void 员工列表() {
        Map<String,Object> map = new HashMap();
        map.put("access_token",getToken2());

        /*map.put("start_time", "1724735500");
        map.put("end_time",   "1724735823");*/
        map.put("limit",   10);
        map.put("offset",   0);

        map.put("fields",   new String[]{"mobile","telephone"});

        String resultStr = HttpUtil.get("https://open.weibanzhushou.com/open-api/staff/list", map);
        JSONObject jsonObject = new JSONObject(resultStr);
        JSONArray staff_list = jsonObject.getJSONArray("staff_list");
        for(int i=0; i<staff_list.size(); i++){
            JSONObject staff = staff_list.getJSONObject(i);
            System.out.println(staff);
            System.out.print(staff.getStr("id")+",");
            System.out.print(staff.getStr("mobile")+",");
            System.out.print(staff.getStr("telephone")+",");
            System.out.println(UnicodeUtil.toString(staff.getStr("name")));

        }

        //wogizUDQAAZoEtX4Qk_UdSraH3fgjRBA,,杨林
        //System.out.println(resultStr);

    }

    public static void 获取客户列表() {
        Map<String,Object> map = new HashMap();
        map.put("access_token",getToken2());

        //map.put("staff_id","LIlina");
        //map.put("phone_number", "18700025094");

        //map.put("staff_id","YangLin");
        map.put("staff_id","wogizUDQAAZoEtX4Qk_UdSraH3fgjRBA");
        //map.put("phone_number", "13572031750");
        //map.put("phone_number", "13279255068");


        String resultStr = HttpUtil.get("https://open.weibanzhushou.com/open-api/external_user/list", map);

        System.out.println(resultStr);

    }
    public static void 查询预打标签() {
        Map<String,Object> map = new HashMap();
        map.put("access_token",getToken2());
        //map.put("type","corp");

        map.put("unionid","oLs8G6O6VgB2mS4wL3HT1SsfaNlE");
        String resultStr = HttpUtil.get("https://open.weibanzhushou.com/open-api/pre_tag/list", map);
        //{"errcode":0,"errmsg":"ok","task_info":[]}

        System.out.println(resultStr);
    }
    public static void 删除客户的企业标签() {
        JSONObject body = new JSONObject();
        body.set("staff_id", "wogizUDQAAZoEtX4Qk_UdSraH3fgjRBA");//
        body.set("tag_group", "来源App标签同步2");
        body.set("tag_name", "WE+生效会员");
        body.set("external_user_unionid", "oLs8G6MzCqaFziu-qf6ptdTQ8M4M");
        body.set("external_user_openid", "o71Lc4sDSQkSoQZuoImzFGWXsBgQ");
        JSONObject resultStr = HttpUtils.sendPost("https://open.weibanzhushou.com/open-api/tag/remove?access_token="+getToken2(), body);
        System.out.println(resultStr);
    }
    public static void 删除预打标签任务() {
        Map<String,Object> map = new HashMap();
        map.put("access_token",getToken2());
        map.put("unionid", "oLs8G6HfK3nBD82S4pehX08LiFFU");
        //map.put("tag_id", "etgizUDQAAg6lolhMWN6FWBV8EG4qr_A");
        String resultStr = HttpUtil.get("https://open.weibanzhushou.com/open-api/pre_tag/remove/unionid", map);
        System.out.println(resultStr);
    }
    public static void 批量预打标() {
        /*JSONObject body = new JSONObject();
        Tag tag = new Tag();
        tag.setId(102522083);
        tag.setName("健萌会员");
        tag.setGroup_name("来源App标签同步2");
        body.set("tag", tag);
        Map<String,String> map = new HashMap<>();
        map.put("unionid","oLs8G6GcfmKexqnj0Ut5UwptwB4c");
        map.put("openid","o71Lc4sqFIlFZs8IT7-rC9_jKrlc");
        body.set("unionid_openid_list", new Map[]{map});*/

        JSONObject body = new JSONObject("{\"tag\":{\"id\":101853456,\"name\":\"华为\",\"group_name\":\"来源App标签同步1\"},\"unionid_openid_list\":[{\"unionid\":\"oLs8G6HkE69YA936cWLFwpDMOBWU\",\"openid\":\"o71Lc4ouzxxeQhm971kK5JkcGxaU\"},{\"unionid\":\"oLs8G6L97cn5yD-oveTRpreLjeGA\",\"openid\":\"o71Lc4pSTmI5lm7ZwVOfkEKBNFlw\"},{\"unionid\":\"oLs8G6AtkovCmHMHhgCTgZzw6lhQ\",\"openid\":\"o71Lc4mpOk5PqS_K6vlFQb8uapcA\"},{\"unionid\":\"oLs8G6MV61djLR0wGu5cm1qJ3u8g\",\"openid\":\"o71Lc4q40XEUj9tIONNs1fuG-my8\"},{\"unionid\":\"oLs8G6G4NH_noLxSeJt6GPKuTd-o\",\"openid\":\"o71Lc4jsrnUu2iiukBTSYudlMZUY\"},{\"unionid\":\"oLs8G6JG4bW3_gTmYTzClVRmaKqs\",\"openid\":\"o71Lc4oDaSbo3-8sHfGqaryy4jCs\"},{\"unionid\":\"oLs8G6LEYVJj16sYHNYSo5KLHry4\",\"openid\":\"o71Lc4ulrKht4ij9-m-xfmFCbr5Q\"},{\"unionid\":\"oLs8G6PS4pb0ypW_MQddjaULC0jU\",\"openid\":\"o71Lc4tYLG0wIgb25C02ANRptSX4\"},{\"unionid\":\"oLs8G6N70s3o4rGOCDUZGt5YIIsg\",\"openid\":\"o71Lc4qw8qgXZK8MrVAj_-wIrH0Q\"},{\"unionid\":\"oLs8G6CTp_FKVHa0MqFH1SwE92vM\",\"openid\":\"o71Lc4v_0_dzh2q8QLZR_mxh2HN4\"},{\"unionid\":\"oLs8G6GQdVRkelpMOMPk3Wcovn-o\",\"openid\":\"o71Lc4iMAJyv0M-tlw1MKyRTUBx0\"},{\"unionid\":\"oLs8G6NWJdzr9qtjcaFFxkaglz6w\",\"openid\":\"o71Lc4sV0qVVzE9yXFX9Bi4zzysI\"},{\"unionid\":\"oLs8G6BXdRMZWxKZaTCPwn7m5Ylo\",\"openid\":\"o71Lc4sI_zc-f1DLL5t-SHbu_43Q\"},{\"unionid\":\"oLs8G6E0HS_mjXBCWHZ-MuCodVaw\",\"openid\":\"o71Lc4jtiF7hU9A0HoC26folEwuU\"},{\"unionid\":\"oLs8G6Oazrcheto5gdVJpCcJ0wzk\",\"openid\":\"o71Lc4lQrhgnXMmt-lXRNG6qAU1A\"},{\"unionid\":\"oLs8G6JOQb3M0v1X0SgESs2w9h6I\",\"openid\":\"o71Lc4kFKI5_WfDLXXtJFQZ20KjA\"},{\"unionid\":\"oLs8G6GsGFLWuf0EyjtZcfTUG-iE\",\"openid\":\"o71Lc4rKY-GRzWcWUeQVkL20b7_4\"},{\"unionid\":\"oLs8G6GXbHS5KwR7vod_LlpFmln4\",\"openid\":\"o71Lc4hnYncE5bGNs7aspIE-Mzbo\"},{\"unionid\":\"oLs8G6F3bgN4Ra3u7bfuB-0Tc7_w\",\"openid\":\"o71Lc4pwJZioYdA1MRtd3JOXzPx4\"},{\"unionid\":\"oLs8G6E6g428etE6ktXbf1dgNDJY\",\"openid\":\"o71Lc4rktEUSvrlOuycmaVOYZ7yE\"},{\"unionid\":\"oLs8G6EPjxFTalj1s8VCGxbebziA\",\"openid\":\"o71Lc4kbwDCv4FEQ82eb57yAPqpg\"},{\"unionid\":\"oLs8G6BLBJugeyhA5_XAuGugw2-I\",\"openid\":\"o71Lc4gc4oXvvR79GxL0x9A-YXWg\"},{\"unionid\":\"oLs8G6EHaPALvryztGzP67xd8Gb0\",\"openid\":\"o71Lc4hKZs9J20yeVlHSFwFDO90s\"},{\"unionid\":\"oLs8G6CRLwW8Xotl5UkR4F-k_rug\",\"openid\":\"o71Lc4tIrv5JVEibsUWEBBdhAp0g\"},{\"unionid\":\"oLs8G6GmxAAcubrgqQs8PVEdwSoU\",\"openid\":\"o71Lc4gw37XVazTSAHgSn2hJkPEU\"},{\"unionid\":\"oLs8G6LRayAtIiFeKudE4cNfn1JM\",\"openid\":\"o71Lc4iyIw5hB-eEEoUGGcwFmkB4\"},{\"unionid\":\"oLs8G6IcFa5l9UIGxtm61cTpF28o\",\"openid\":\"o71Lc4pflxkb0YKqVOMnrm8saTb4\"},{\"unionid\":\"oLs8G6ChZ4HIXdBzp4GyM07un4I8\",\"openid\":\"o71Lc4mnvL6V5_XcoFf2tZvK2MCU\"},{\"unionid\":\"oLs8G6OXPsvGzMH9I3QzeDokTjgQ\",\"openid\":\"o71Lc4owfyfZ2N-mNtb6MjuGhB9A\"},{\"unionid\":\"oLs8G6NI6Xu7NqTgOidpo4hW_Ass\",\"openid\":\"o71Lc4tFMKnKojfRkW7LMwI-oyV0\"},{\"unionid\":\"oLs8G6AQFPMlkgsY-_zdHj7fjOLo\",\"openid\":\"o71Lc4oJ8hiwUPvc_KoiU16U9SHg\"},{\"unionid\":\"oLs8G6PTUlagaTy5w31HAE3hMLQM\",\"openid\":\"o71Lc4kOOHX6tttTH1yt6s63pAwM\"},{\"unionid\":\"oLs8G6Kx4kM-PF3sLCPg2wMQE9R8\",\"openid\":\"o71Lc4vifbTQsFNw14iPkns-c8kQ\"},{\"unionid\":\"oLs8G6Gx2lYmH9WnkiWb3xrs3zXs\",\"openid\":\"o71Lc4i8-itPnh5-_Rt2dGnyIcs4\"},{\"unionid\":\"oLs8G6OrBbWfWhcnYsaAnlmU7LY8\",\"openid\":\"o71Lc4tjFfolhJGndECguDGV12BQ\"},{\"unionid\":\"oLs8G6BPZOaHp0X35-6JkaYbqFU0\",\"openid\":\"o71Lc4umaBfX-sxkB1zQOReaADP0\"},{\"unionid\":\"oLs8G6MDPwOikqV-Ki9HAUX_r3us\",\"openid\":\"o71Lc4pcf3-reECVQdPyA0Rl3s8w\"},{\"unionid\":\"oLs8G6Pw9B8QcJqWbjD1uwP5BUBw\",\"openid\":\"o71Lc4jIurRX85othb_VbiEioFfA\"},{\"unionid\":\"oLs8G6GR8SNGViLtTmeJZALV25fI\",\"openid\":\"o71Lc4rEo5nms5R9iHgdZopRKadE\"},{\"unionid\":\"oLs8G6GuMWuHSr-ZVPJrWHpcYWlM\",\"openid\":\"o71Lc4rMwSEX2RjIJaCr-IofNXuE\"},{\"unionid\":\"oLs8G6KCIek05Jzka0za0dmNK16Q\",\"openid\":\"o71Lc4qtN_jZRpLxorIVmIeWaM3c\"},{\"unionid\":\"oLs8G6FnXTs5w555SEghNQ_CAF5Y\",\"openid\":\"o71Lc4okmeZVSUCJXC4oXlmXwB_c\"},{\"unionid\":\"oLs8G6LkGnQWx4YNn_UP4QDpsano\",\"openid\":\"o71Lc4mMm56MXNwBPqYLfIhCkhhE\"},{\"unionid\":\"oLs8G6PV5NHJ4GbU7sQOYEZwQP7s\",\"openid\":\"o71Lc4tpNrOlB8qPMIfqhOVIjenE\"},{\"unionid\":\"oLs8G6EqVMfGfmEb8mM7tRA86KVE\",\"openid\":\"o71Lc4mpwxDEips7ssGsXcrvYZOc\"},{\"unionid\":\"oLs8G6IdA3vn2GoUtXRUvti0jcpk\",\"openid\":\"o71Lc4p1kQ19BH1-sMm3HwfMQZUM\"},{\"unionid\":\"oLs8G6AvZIMHAd8-H3V0A3Mve6OE\",\"openid\":\"o71Lc4n8C2OUvzBsG5WAZjxIVDdI\"},{\"unionid\":\"oLs8G6LiaCyT9AlnBSLcxSGPnlJg\",\"openid\":\"o71Lc4qgoVEWNnIuHDKGDdNKzNIY\"},{\"unionid\":\"oLs8G6PNIyswJrpVr7CcNoEGYrUg\",\"openid\":\"o71Lc4k5PDltaSLPv9__wRh-X2T4\"},{\"unionid\":\"oLs8G6JjTt4yRnZ912sP1DBAIomc\",\"openid\":\"o71Lc4ivGOfevbr3izWLm_5mkjX8\"},{\"unionid\":\"oLs8G6CsQmjIs0G9ASIFJTqMCVa8\",\"openid\":\"o71Lc4oxO1tGMtLwFNQwTLHwtmmo\"},{\"unionid\":\"oLs8G6I0ox1VnlRqbZ9xSHCNDQkQ\",\"openid\":\"o71Lc4lvbhmHJOMoNvjPE3kgA-mA\"},{\"unionid\":\"oLs8G6FjVQ7_dm7GtVns2A-_X8kE\",\"openid\":\"o71Lc4l8N8H2ES1hYREhCCM6ibco\"},{\"unionid\":\"oLs8G6Dv1Nma3awwiYESoV3bnZiY\",\"openid\":\"o71Lc4kJMUePwAg1l6jmG26nBcm0\"},{\"unionid\":\"oLs8G6FgXrWhY8vrPoLATuCY80LU\",\"openid\":\"o71Lc4hph0yZwHtV2ZKC21SOXoOQ\"},{\"unionid\":\"oLs8G6KPBeP-ENdUQGrT36sRo0_k\",\"openid\":\"o71Lc4hwXfICkifVDV2dn3TAIEQE\"},{\"unionid\":\"oLs8G6FFvYa-WmOwOtm0LfTperRc\",\"openid\":\"o71Lc4mni9syd3KACLEg3mzvmZlA\"},{\"unionid\":\"oLs8G6P7t-FZJvW0E_GDtbkl6gvE\",\"openid\":\"o71Lc4u-f0uKJtgYvSRnpiNFEJEI\"},{\"unionid\":\"oLs8G6Do13MAjuSJCcuzzakver6c\",\"openid\":\"o71Lc4mvOdepLsn9gkdKZQraZNhY\"},{\"unionid\":\"oLs8G6OLc12cmAoNPshVjzv8L48Q\",\"openid\":\"o71Lc4r6ss8yG4LDAhf_jhM3R010\"},{\"unionid\":\"oLs8G6EO5-EcyGsLEV5wvHkVcYnk\",\"openid\":\"o71Lc4nEgP8gvit2OPDtvT3zb38Q\"},{\"unionid\":\"oLs8G6B8Z8V1J2J_3PhqYXNr2zh0\",\"openid\":\"o71Lc4uKipg3dNQd5o8GLSgkdYcU\"},{\"unionid\":\"oLs8G6N6w6kas-4Vk7qZSSHEe5Qs\",\"openid\":\"o71Lc4q2tl-CpgFUjhQV-1GAltbk\"},{\"unionid\":\"oLs8G6CbbjjocPI5HQv0wfSDjjG4\",\"openid\":\"o71Lc4mclsTyJNsqLoabobO367p0\"},{\"unionid\":\"oLs8G6LVEGlNLOk6Tq5wIRIM2PFU\",\"openid\":\"o71Lc4mnrT7eZWIbyiDyEmtzCxrQ\"},{\"unionid\":\"oLs8G6AZ_QJGWFr_5dLF9QDPHy4w\",\"openid\":\"o71Lc4kVOuC8Vlz4JYAOKYMapN-I\"},{\"unionid\":\"oLs8G6PYL1R27xXSklCoAo-iWagA\",\"openid\":\"o71Lc4kfb6yj-pAiJz7UF44nokzU\"},{\"unionid\":\"oLs8G6A0sRRZVUa-rDA7KBTcu5aI\",\"openid\":\"o71Lc4j3nnsUQi5smz9dPEe3LzGg\"},{\"unionid\":\"oLs8G6DwDRPsbLva1fP-rnnhqc8w\",\"openid\":\"o71Lc4rlHrJnJqoZybLIyCEl5yD8\"},{\"unionid\":\"oLs8G6Lqa4WqEIW8F_0nQcuQy6uc\",\"openid\":\"o71Lc4rYaMT4h9bLQL6chwZiW6zo\"},{\"unionid\":\"oLs8G6OZOnMDB8BNVCUQW3rWsrbs\",\"openid\":\"o71Lc4mw4D8tR3DV4csQ9Zk9guH0\"},{\"unionid\":\"oLs8G6Mkm4iIDomtwDrbPF8ki36k\",\"openid\":\"o71Lc4hIJzZTef8aiYLGoEtVZi-U\"},{\"unionid\":\"oLs8G6B6d0-JzFojpaWYh_CsMe1c\",\"openid\":\"o71Lc4mXwhWeZi5M_bbaW6T5ypTQ\"},{\"unionid\":\"oLs8G6AIqZ_rqMlpo3d3hHPANVhI\",\"openid\":\"o71Lc4n6-FDl_QQX3LoEDWshVaqY\"},{\"unionid\":\"oLs8G6DMAjYGUg8GIdypSFg1p5gs\",\"openid\":\"o71Lc4npAFhtAoks_GYr-dJKVUHg\"},{\"unionid\":\"oLs8G6IuF_JFnb8-dL6rUi8xO1NQ\",\"openid\":\"o71Lc4iHIVeY9DgZgZ4XecjPmtSc\"},{\"unionid\":\"oLs8G6BP9ruR06z06TPcAO2DYvZo\",\"openid\":\"o71Lc4i9ILSGux_611LaLiXdPauw\"},{\"unionid\":\"oLs8G6H_EacRvLchfAIHKFMEaku4\",\"openid\":\"o71Lc4mebYGwxeoqascY3lTOUapc\"},{\"unionid\":\"oLs8G6HM3-S7yG4mY6_rCZbvZgdw\",\"openid\":\"o71Lc4tzylPMWLAWEtlL2FVMWyas\"},{\"unionid\":\"oLs8G6ObraYK7A0wvM-Zm7GMR5o4\",\"openid\":\"o71Lc4tRTc7wLmMWDxAiZ6HEWIqY\"},{\"unionid\":\"oLs8G6A3tzp_w8XyFcuvHk3MuIu0\",\"openid\":\"o71Lc4jJEkQbwoMWD0nq4uLSsyB0\"},{\"unionid\":\"oLs8G6DP0g6QcvTu7u7rC9G2m3jE\",\"openid\":\"o71Lc4qKng8ga0T2CRbwDkkD04r4\"},{\"unionid\":\"oLs8G6NUj7Zb3dIlw78uc4e3WcKs\",\"openid\":\"o71Lc4iWOb9CEz9vdk13EeNuYqGE\"},{\"unionid\":\"oLs8G6M8sEbuLFFtGVFrtl_G0uzs\",\"openid\":\"o71Lc4iacLfLTTS4THbIVvXTEVTw\"},{\"unionid\":\"oLs8G6LXNIBtjRXquFEZvSAsvhJU\",\"openid\":\"o71Lc4sFY66Mp7TG3AI0I6w08bL4\"},{\"unionid\":\"oLs8G6LG8j9BA0sf0NIuu2KyDXHc\",\"openid\":\"o71Lc4ud0ST1y4lI2y4vHSdx4zOM\"},{\"unionid\":\"oLs8G6EPsQQC-Xfq3nv3eXZzhq6o\",\"openid\":\"o71Lc4lbBF79SKxFnPmvJL5D59dM\"},{\"unionid\":\"oLs8G6Gyrmo4XAtzbFkFFi8Ft2ak\",\"openid\":\"o71Lc4uzfdjn_0RuSM4TbsCn2f34\"},{\"unionid\":\"oLs8G6Ix6Ygw4JSA0uK5_xcb4BRs\",\"openid\":\"o71Lc4r8OB5VV2GqMfa6X9DfRn0U\"},{\"unionid\":\"oLs8G6C-1MSJsXEBcRBeqB3lFDd8\",\"openid\":\"o71Lc4jweZcSriVaq0kVFABxvMFw\"},{\"unionid\":\"oLs8G6Pbd1COYR4D9iOPZuul0P2M\",\"openid\":\"o71Lc4k2_b3m7f5AGDCfaVeI27vc\"},{\"unionid\":\"oLs8G6A_N-LN3ox7B89zW7ccX2Cc\",\"openid\":\"o71Lc4j4CRY1aqL4PfHfo_xWZwmE\"},{\"unionid\":\"oLs8G6MhD_TKkO9xouAKHeoygJc4\",\"openid\":\"o71Lc4gtuPXQFfJ12PZCcCZMLpgU\"},{\"unionid\":\"oLs8G6AtQGuLcNboQS04z280Zx4U\",\"openid\":\"o71Lc4qIIABjBPlKdyz_xhVLNGxU\"},{\"unionid\":\"oLs8G6L4oRyuAEfFpZ8KqX7oNi4M\",\"openid\":\"o71Lc4n1YKlRHcxYvBKeDtbWbrLo\"},{\"unionid\":\"oLs8G6F50TSx3H95yn9kkzZamp2Q\",\"openid\":\"o71Lc4pZ9bexS5zhYbK5cp3RPer8\"},{\"unionid\":\"oLs8G6O7xER4NlH7VEAHjcmoGuZI\",\"openid\":\"o71Lc4q3xAJz6DFJp2hascTFsYco\"},{\"unionid\":\"oLs8G6AfH1eODlPA1HscCiofZHME\",\"openid\":\"o71Lc4viztovT9KogptfxEjFawkY\"},{\"unionid\":\"oLs8G6KPdyHHGDHdK-Cyi4JZOlM4\",\"openid\":\"o71Lc4rM6K5W3zmkMOJelI0nuPhk\"},{\"unionid\":\"oLs8G6EUfxnCRYvzBod58HXkpKFo\",\"openid\":\"o71Lc4jFP4l2v4kDNXVSY7Ev9KOk\"},{\"unionid\":\"oLs8G6Drw7CuozzLVh19_hqOLSxo\",\"openid\":\"o71Lc4oY7gFkCHqt-pVyuO_eV8LU\"},{\"unionid\":\"oLs8G6Bj1yLDiAbGS2euj222UnjA\",\"openid\":\"o71Lc4hLhQUVEu94qd7_Z1l-ASsk\"},{\"unionid\":\"oLs8G6KSusaGQAXGYt44JDs_5ywg\",\"openid\":\"o71Lc4u8mSI9gzBSLmwKVmf0WTF0\"},{\"unionid\":\"oLs8G6PzzE2TzLPsGmW4HVvAZrbg\",\"openid\":\"o71Lc4hJ0vNQPXQi9zifXrURMpqw\"},{\"unionid\":\"oLs8G6FBhJOceKfomejrfL9lqGLw\",\"openid\":\"o71Lc4oUal_xuF91A5e33zDRrdUg\"},{\"unionid\":\"oLs8G6HnTCftOh4J88buIL8iPm0Y\",\"openid\":\"o71Lc4ksAThXmJ6g84h0do13i0d4\"},{\"unionid\":\"oLs8G6FY1gUmhEdkxjLg-LpyNncI\",\"openid\":\"o71Lc4oLdbW5E6MSn2HiY728hPyk\"},{\"unionid\":\"oLs8G6PvRXpPN6yZncfqItezl5CU\",\"openid\":\"o71Lc4veI3lSxiNTeZstZROSOGRU\"},{\"unionid\":\"oLs8G6FzCVSjg_h6ukFwbrOJvz5Y\",\"openid\":\"o71Lc4nhYWnRqaPTQSzZ468Cd_ds\"},{\"unionid\":\"oLs8G6P32Z3iiT_oUF1cyjHjc47c\",\"openid\":\"o71Lc4rZBJDVK2JOOyeGVrxO5mk4\"},{\"unionid\":\"oLs8G6LLOATpF9gG_Wfh8CZvyR_o\",\"openid\":\"o71Lc4kzAxKziFNSornm5M8AD-IM\"},{\"unionid\":\"oLs8G6DXdIZjVgN6XYo-BtOFvjqA\",\"openid\":\"o71Lc4nmcLyg8qUxHT76A5CQ__Xo\"},{\"unionid\":\"oLs8G6LEm37dfCnyzWUd2vA5jCu8\",\"openid\":\"o71Lc4m2YtfGnY-BLDd4Eeh1vfOE\"}]}");
        System.out.println(body);
        JSONObject resultStr = HttpUtils.sendPost("https://open.weibanzhushou.com/open-api/wx_user/mark_tag?access_token="+getToken2(), body);

        System.out.println(resultStr);
    }

    static class Tag {
        private Integer id;
        private String name;
        private String group_name;
        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getGroup_name() {
            return group_name;
        }

        public void setGroup_name(String group_name) {
            this.group_name = group_name;
        }
    }

    public static void 任务详情() {
        Map<String,Object> map = new HashMap();
        map.put("access_token",getToken2());
        //{"errcode":10049,"errhint":"LQ33N","errmsg":"\u53c2\u6570\u9519\u8bef","errors":[
        //{"ctx":{"enum_values":["unionid","mobile","wx_staff","group"]},"loc":["type"],"msg":"value is not a valid enumeration member;
        //permitted: 'unionid', 'mobile', 'wx_staff', 'group'","type":"type_error.enum"}]}
        /*map.put("type","mobile");
        map.put("value","18008408952");*/
        map.put("type","unionid");
        map.put("value","oLs8G6MzCqaFziu-qf6ptdTQ8M4M");
        String resultStr = HttpUtil.get("https://open.weibanzhushou.com/open-api/get/pre_tag/detail", map);
        //{"errcode":0,"errmsg":"ok","mark_list":[{"create_at":1719482625.0,"has_marked":true,"tag_ids":["etgizUDQAAriaSO1kQVHCctmARFsuSTg"]},{"create_at":1719482765.0,"has_marked":true,"tag_ids":["etgizUDQAAmlZdRdvBgrwwIrcm3cQZGw"]},{"create_at":1719802875.0,"has_marked":true,"tag_ids":["etgizUDQAAmlZdRdvBgrwwIrcm3cQZGw"]},{"create_at":1719900226.0,"has_marked":true,"tag_ids":["etgizUDQAAxbFjGebneZYJLeZISIGuLw"]}],"value":"18008408952"}
        System.out.println(resultStr);
        //{"errcode":0,"errmsg":"ok","mark_list":[{"create_at":1724751194.0,"has_marked":true,"tag_ids":["etgizUDQAA6Cmj_rl7kiVGK2Se2-V5mA"]}],"value":"oLs8G6MzCqaFziu-qf6ptdTQ8M4M"}
        //{"errcode":0,"errmsg":"ok","mark_list":[{"create_at":1724808106.0,"has_marked":true,"tag_ids":["etgizUDQAAg6lolhMWN6FWBV8EG4qr_A"]},{"create_at":1724808176.0,"has_marked":true,"tag_ids":["etgizUDQAAMRR8yC8moC7b-uUj3XuHlA"]},{"create_at":1724808026.0,"has_marked":true,"tag_ids":["etgizUDQAAjuZ6zVPGKOLY2vsskB9q3g"]}],"value":"oLs8G6MzCqaFziu-qf6ptdTQ8M4M"}
        //当该unionid无预打标签任务是报错：{"errcode":20361,"errhint":"MMmu2","errmsg":"value\u975e\u6cd5"}
    }


    public static void 同步微伴标签() throws IOException {
        Map<String,Object> map = new HashMap();
        map.put("access_token",getToken2());
        map.put("limit","100");
        //{"errcode":0,"errmsg":"ok","tag_list":[{"t_id":101437649,"tag_id":"etgizUDQAAcFRlE8v4IBP5_iKkgC114A","tag_name":"一般","tag_group_id":"etgizUDQAAKieBN6wqjpiBQE2I3rWUDA","tag_group_name":"客户等级","departmend_list":["0"]},{"t_id":101437650,"tag_id":"etgizUDQAA_8Wzaz88r-zNWLqQL2ozvw","tag_name":"重要","tag_group_id":"etgizUDQAAKieBN6wqjpiBQE2I3rWUDA","tag_group_name":"客户等级","departmend_list":["0"]},{"t_id":101437651,"tag_id":"etgizUDQAAeAZ6acS4sOVDtBJE7GhV3g","tag_name":"核心","tag_group_id":"etgizUDQAAKieBN6wqjpiBQE2I3rWUDA","tag_group_name":"客户等级","departmend_list":["0"]},{"t_id":101525540,"tag_id":"etgizUDQAASnJqBrEnnjI4oIQhMpnW0g","tag_name":"个人：多囊","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101525545,"tag_id":"etgizUDQAASZOD1ShQGJ_GOIxmUpgQOw","tag_name":"年龄35+","tag_group_id":"etgizUDQAAnagkbugP78KC3GvYj_fekw","tag_group_name":"达人组","departmend_list":["0"]},{"t_id":101539080,"tag_id":"etgizUDQAAduBYbINAr-nBo-sWEphHUg","tag_name":"已购","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539081,"tag_id":"etgizUDQAAmPQhn5z_46G7LfA9WSvNzw","tag_name":"不回复","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539082,"tag_id":"etgizUDQAAdfguGcWEVb3VtDnhcP2kaQ","tag_name":"未成年学生","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539083,"tag_id":"etgizUDQAAriaSO1kQVHCctmARFsuSTg","tag_name":"成年学生","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539084,"tag_id":"etgizUDQAASneeYy5_r84zZvgorEvVyQ","tag_name":"个人：年龄35+","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539085,"tag_id":"etgizUDQAAv_gcmu_0tvZClbBHYTTnbw","tag_name":"不符合入营要求","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539086,"tag_id":"etgizUDQAA1swrX54eTjrbGSzArClPmA","tag_name":"报过减脂营","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539087,"tag_id":"etgizUDQAAmlZdRdvBgrwwIrcm3cQZGw","tag_name":"大基数","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539088,"tag_id":"etgizUDQAAQeEfVbXZQ5oDjECApxnJug","tag_name":"小基数","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539089,"tag_id":"etgizUDQAAbrkwP1TqArIa_FSPJ3On4g","tag_name":"A类","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539090,"tag_id":"etgizUDQAAgyKDN3RxmLdT4Fhw33HGgw","tag_name":"B类","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539091,"tag_id":"etgizUDQAAWV0b1ItrVFB_vIwCEsWxrA","tag_name":"C类","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539092,"tag_id":"etgizUDQAAbCXH7nFmCcK5RJBc6SE4zw","tag_name":"个人：男性","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539093,"tag_id":"etgizUDQAAYCf9kk1DFAivdizB-rQtBQ","tag_name":"个人：备孕","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539094,"tag_id":"etgizUDQAAENlU24-WqOxdh3U0jAjVWw","tag_name":"个人：咨询营养师证","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539095,"tag_id":"etgizUDQAAxTTao4Qbr8v9M1OsXRHNTA","tag_name":"个人：产后/宝妈","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539096,"tag_id":"etgizUDQAA2rvd-z3ILwRkcUdmYGNpWg","tag_name":"已流失","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539097,"tag_id":"etgizUDQAAun-xYcGozUB--ZXLtDDJJA","tag_name":"可删","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]},{"t_id":101539549,"tag_id":"etgizUDQAAGF8rWUMAuSdzdLysrHQIiA","tag_name":"多囊","tag_group_id":"etgizUDQAAnagkbugP78KC3GvYj_fekw","tag_group_name":"达人组","departmend_list":["0"]},{"t_id":101564897,"tag_id":"etgizUDQAApQbCBOm3599EYskDJfUGvw","tag_name":"信息流","tag_group_id":"etgizUDQAAvpB1UlbBkW3iGOVyR5ecBA","tag_group_name":"售前私域-达人渠道","departmend_list":["0"]},{"t_id":101564898,"tag_id":"etgizUDQAADm6tTLxD4N3MZvgtjzL-UA","tag_name":"抖店","tag_group_id":"etgizUDQAAvpB1UlbBkW3iGOVyR5ecBA","tag_group_name":"售前私域-达人渠道","departmend_list":["0"]},{"t_id":101564899,"tag_id":"etgizUDQAAkR-McOJVQVksV0ZHoYpgHg","tag_name":"体脂秤","tag_group_id":"etgizUDQAAvpB1UlbBkW3iGOVyR5ecBA","tag_group_name":"售前私域-达人渠道","departmend_list":["0"]},{"t_id":101565320,"tag_id":"etgizUDQAAEFP_3QBapbuCUyPc3Geahg","tag_name":"苹果型","tag_group_id":"etgizUDQAAnagkbugP78KC3GvYj_fekw","tag_group_name":"达人组","departmend_list":["0"]},{"t_id":101565321,"tag_id":"etgizUDQAAHBCWcLl-CsM8VzjcRA6cgw","tag_name":"梨形","tag_group_id":"etgizUDQAAnagkbugP78KC3GvYj_fekw","tag_group_name":"达人组","departmend_list":["0"]},{"t_id":101565322,"tag_id":"etgizUDQAA9AcJxTHuK09We0_gSLVkjw","tag_name":"个人：苹果型","tag_group_id":"etgizUDQAA1n1dhMyirC9nvux-p_RQZA","tag_group_name":"APP组","departmend_list":["0"]}],"total":997}
        FileWriter fileWriter = new FileWriter("E://来源App标签同步3.txt");
        for(int i=16;i<24;i++){
            map.put("offset",i*100);
            String resultStr = HttpUtil.get("https://open.weibanzhushou.com/open-api/tag/list", map);
            System.out.println(resultStr);
            JSONObject jsonObject = new JSONObject(resultStr);
            JSONArray tag_list = jsonObject.getJSONArray("tag_list");

            System.out.println(","+tag_list.size());
            for(int j=0;j<tag_list.size();j++){
                JSONObject tag = tag_list.getJSONObject(j);

                //System.out.println(tag);
                if(tag.getStr("tag_group_name").startsWith("来源App标签同步2")){
                    fileWriter.write(tag.getStr("t_id"));
                    fileWriter.write("\t");
                    fileWriter.write(tag.getStr("tag_id"));
                    fileWriter.write("\t");
                    fileWriter.write(tag.getStr("tag_name"));
                    fileWriter.write("\t");

                    fileWriter.write(tag.getStr("tag_group_id"));
                    fileWriter.write("\t");
                    fileWriter.write(tag.getStr("tag_group_name"));
                    fileWriter.write("\t");

                    fileWriter.write("\n");
                }

            }
            if(tag_list.size()<100){
                break;
            }
        }

        fileWriter.flush();
        fileWriter.close();

    }

    private JSONObject 调注册方法(){
        JSONObject body = new JSONObject();//post请求的body对象
        body.put("corpId", "1792107650729230337");//body属性无顺序，但是要保证请求流的顺序和生成签名的顺序一致
        body.put("secret", "6c99b10cc08cb30c3ae39efc68ac83be");

        String secret = "这里是私钥";
        //签名算法直接拼接md5即可
        String sign = MD5.create().digestHex(body +"#"+secret);
        JSONObject header = new JSONObject();//请求头部
        header.put("X-SIGN",sign);//把签名信息放到头部
        header.put("X-TRACEID", UUID.randomUUID());//这里是请求UUID，用于链路追踪
        header.put("X-APPKEY", "10067615200");//这里是公钥--接口提供放，通过公钥去找到对应的私钥验签
        JSONObject result =sendRequest("apiUrl", header, body, "POST");
        return result;
    }
    public static JSONObject sendRequest(String uri, JSONObject header, JSONObject body, String requestMethod){
        HttpURLConnection connection = null;
        try {
            URL url = new URL(uri);
            connection = (HttpURLConnection)url.openConnection();
            connection.setDoInput(true);
            connection.setDoOutput(true);
            connection.setRequestMethod(requestMethod);
            connection.setUseCaches(false);
            connection.setInstanceFollowRedirects(true);
            connection.setRequestProperty("Content-Type","application/json; charset=UTF-8");
            connection.setConnectTimeout(3000);// 10秒 连接超时时间（单位毫秒）
            connection.setReadTimeout(5000);// 5秒 读取数据超时时间（单位毫秒）

            //设置header
            if(header != null){
                final Set<String> keySet = header.keySet();
                for(String key:keySet) {
                    connection.setRequestProperty(key,header.getStr(key));
                }
            }
            connection.connect();
            System.out.println("sendPost uri=" + uri +",param="+ body.toJSONString(0) + ",header=" + header);
            DataOutputStream out = new DataOutputStream(connection.getOutputStream());
            out.write(body.toJSONString(0).getBytes());
            out.flush();
            out.close();

            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String lines;
            StringBuffer sb = new StringBuffer("");
            while((lines=reader.readLine())!=null){
                lines = new String(lines.getBytes(StandardCharsets.UTF_8));
                sb.append(lines);
            }
            reader.close();
            connection.disconnect();
            System.out.println("sendRequest result:" + sb);
            return new JSONObject(sb);
        }catch (SocketTimeoutException e){
            System.out.println("连接超时异常");
        }catch (Exception e){
            System.out.println("sendRequest uri=" + uri +",param="+ body.toJSONString(0) + ",header=" + header+",happen exception.");
            e.printStackTrace();
        }finally {
            if(connection != null){
                try {
                    connection.disconnect();
                }catch (Exception e){}
            }
        }
        return null;
    }

    static String getToken2(){
        if("1".equals("")){
            return "f6020abbc2a8e86ef2633b616d32e946";
        }
        JSONObject body = new JSONObject();
        /*body.set("corpId", "1792107650729230337");
        body.set("secret", "6c99b10cc08cb30c3ae39efc68ac83be");*/

        String sign = MD5.create().digestHex(body +"#5601291336c76762f1d56ce5b45b2419");
        JSONObject header = new JSONObject();
        header.set("X-SIGN",sign);
        header.set("X-TRACEID", UUID.randomUUID());
        header.set("X-APPKEY", "10067615200");
        JSONObject result = HttpUtils.sendPost("https://wedata.gymcity.com.cn/openapi/third/getWeibanToken", header, body);
        return result.getJSONObject("data").getStr("access_token");
        //sendRequest result:{"code":200,"msg":"操作成功","data":{"access_token":"8b64b60bcefa0b6241a3b1e93ffc6238","errcode":0,"errmsg":"ok","expires_in":7200},"time":1724651493}
        //sendRequest result:{"code":200,"msg":"操作成功","data":{"access_token":"9d6cb26fc748610350a5cfb1e1bc512b","errcode":0,"errmsg":"ok","expires_in":7200},"time":1725427186}
        //sendRequest result:{"code":200,"msg":"操作成功","data":{"access_token":"9d6cb26fc748610350a5cfb1e1bc512b","errcode":0,"errmsg":"ok","expires_in":7131},"time":1725427255}
    }

    private static String getToken(){
        JSONObject body = new JSONObject();
        body.set("corp_id", "1792107650729230337");
        body.set("secret",  "6c99b10cc08cb30c3ae39efc68ac83be");
        JSONObject header = new JSONObject();
        JSONObject result = HttpUtils.sendPost("https://open.weibanzhushou.com/open-api/access_token/get", header, body);
        System.out.println(result);
        return result.getStr("access_token");
        //{"errcode":0,"errmsg":"ok","access_token":"8a1f284ec4228a5ef4043b42fc41e3c7","expires_in":7200}
        //{"errcode":0,"errmsg":"ok","access_token":"8a1f284ec4228a5ef4043b42fc41e3c7","expires_in":7187}
        //{"errcode":0,"errmsg":"ok","access_token":"8a1f284ec4228a5ef4043b42fc41e3c7","expires_in":7147}
        //{"errcode":0,"errmsg":"ok","access_token":"71d6cdcb8a27739ef40eb40d076055f6","expires_in":6303}
        //{"errcode":0,"errmsg":"ok","access_token":"71d6cdcb8a27739ef40eb40d076055f6","expires_in":5665}
        //{"errcode":0,"errmsg":"ok","access_token":"7028a98393c29e9ac84988b29f511134","expires_in":7200}
    }

}
